home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / Lotto / lotto.cp < prev    next >
Encoding:
Text File  |  1997-03-17  |  16.6 KB  |  629 lines  |  [TEXT/CWIE]

  1.  
  2.  
  3. #include <iostream.h>
  4. #include <stdlib.h>
  5.  
  6.  
  7. #include "lotto.h"
  8. #include "lotto_calc_class.h"
  9.  
  10.  
  11.  
  12.  
  13. class lotto_calc *calc;
  14. lotto_struct *temp[MAX_STRUCTS];
  15.  
  16. void main( void )
  17. {
  18.     calc = new lotto_calc;
  19.     bool quit = false;
  20.     int choice;
  21.     bool exists = false;
  22.     
  23.     do {
  24.     
  25.         choice = 0;
  26.         
  27.         print_main_menu();
  28.         
  29.         cout << "Choice?: ";
  30.         
  31.         cin >> choice;
  32.         cout << endl << endl;
  33.         switch( choice )
  34.         {
  35.             case 1:
  36.                 {    
  37.                     // check if the file exists, and if so, if the user
  38.                     // wants to over-write it. default is true if no file exists.
  39.                     if( (check_file()) == true )
  40.                         {
  41.                             cout << "Start with the most recent draw and end with the oldest draw" << endl;
  42.                             cout << "Recommended: don't use any draws before 11/27/91 as the oldest draw" << endl;
  43.                             cout << "Enter numbers in the form <number> <dot> <number>" << endl;
  44.                             cout << "Example:  12.17.23.34.42.50" << endl;
  45.                             cout << "Then enter the date (Example: 11/27/91) with slashes" << endl;
  46.                             cout << "Enter a q to quit!" << endl << endl;
  47.                             
  48.                             
  49.                             // init the class vars
  50.                             calc->number_of_records = 0; // we are writing a new database
  51.                             calc->clear_user_input();
  52.                             
  53.                             bool run = true;
  54.                             
  55.                             do {
  56.                                     cout << "Set?: ";
  57.                                     cin >> calc->user_input;
  58.                                     run = ( calc->set_struct_file() );
  59.                                     cout << endl;
  60.                                     
  61.                                     if( run == true )
  62.                                     {
  63.                                         cout << "Date?: ";
  64.                                         cin >> calc->record[calc->number_of_records - 1]->date;
  65.                                     }
  66.                                     cout << endl;
  67.                                     
  68.                                 if( run == true )
  69.                                 {
  70.                                     cout << "Set # " << calc->number_of_records << " is: ";
  71.                                     for( int index = 0; index < 6; index++ )
  72.                                     {
  73.                                         cout << calc->record[calc->number_of_records - 1]->set[index] << ' ';
  74.                                     }
  75.                                     cout << endl;
  76.                                     cout << "Date: " << calc->record[calc->number_of_records - 1]->date;
  77.                                     cout << endl << endl;
  78.                                 }
  79.  
  80.                             } while( run == true );
  81.                             
  82.                             if( (calc->save_whole_file()) == true )
  83.                             {
  84.                                 cout << "Data Saved To Disk!" << endl;
  85.                                 break;
  86.                             } else {
  87.                                 cout << "Error: No Data Written To Disk!!" << endl;
  88.                                 break;
  89.                                 }
  90.                         } else {
  91.                             cout << "No File Written." << endl <<endl;
  92.                             break;
  93.                             }
  94.                     break;
  95.                 }
  96.                 
  97.             case 2: 
  98.             {
  99.                 int answer = 0;
  100.                 
  101.                 if( calc->read_file() == false )
  102.                 {
  103.                     cout << "Error: can not read file!" << endl;
  104.                 } else {
  105.                     cout << "You have " << (calc->number_of_records);
  106.                     cout << " records." << endl;
  107.                     cout << endl;
  108.                     
  109.                 do {
  110.                     cout << "View Which Record? <[ " << calc->number_of_records << " ]> ( 0 to quit ): ";
  111.                     cin >> answer;
  112.                     cout << endl;
  113.                     if( answer > (calc->number_of_records) )
  114.                     {
  115.                         cout << "That record doesn't exist!" << endl;
  116.                         cout << "try again: ";
  117.                         cin >> answer;
  118.                         cout << endl;
  119.                     }
  120.                     if( answer == 0 )
  121.                     {
  122.                         goto theEnd;
  123.                     }
  124.                     
  125.                     cout << "Set # " << answer << " is: ";
  126.                     for( int index = 0; index < 6; index++ )
  127.                     {
  128.                         cout << calc->record[answer - 1]->set[index] << ' ';
  129.                     }
  130.                     cout << endl;
  131.                     cout << "Reds: " << calc->record[answer - 1]->reds << "  ";
  132.                     cout << "Whites: " << calc->record[answer - 1]->whites << "  ";
  133.                     cout << "Blues: " << calc->record[answer - 1]->blues << "  ";
  134.                     cout << endl;
  135.                     cout << "Odds: " << calc->record[answer - 1]->odds << "  ";
  136.                     cout << "Evens: " << calc->record[answer - 1]->evens << "  ";
  137.                     cout << endl;
  138.                     cout << "Date: " << calc->record[answer - 1]->date;
  139.                     cout << endl << endl;
  140.                 } while( answer != 0 );
  141.                 
  142.                 theEnd:
  143.                 
  144.                 if( answer == 0 )
  145.                 {
  146.                     calc->number_of_records = 0;
  147.                     calc->clear_records();
  148.                     break;
  149.                 }
  150.                 }
  151.             calc->number_of_records = 0;
  152.             calc->clear_records();
  153.             break;
  154.             }
  155.             
  156.             case 3:
  157.             {
  158.                 /***************************************************************************
  159.                  this code is intended for allowing user to choose how many numbers to
  160.                  generate.  At this time, more than ten chokes the program.
  161.                  
  162.                  int the_amount = 0;
  163.                 
  164.                  cout << endl;
  165.                  cout << "Generate How Many Numbers? ( 0 for default of 10 ): ";
  166.                  cin >> how_many;
  167.                 
  168.                  if( how_many > 0 )
  169.                  {
  170.                      the_amount = how_many;
  171.                  } else {
  172.                     the_amount = MAX_GEN;
  173.                      }
  174.                  ****************************************************************************/
  175.                 int set_predict[6] = {NULL};
  176.                 int how_many = 0;
  177.                 cout << endl << "Be patient! ... processing data" << endl;
  178.                 if( (calc->make_numbers( how_many )) == false )
  179.                 {
  180.                     cout << "Error: not enough data in database!" << endl;
  181.                     break;
  182.                 } else {
  183.                     cout << endl << endl;
  184.                     for( int index = 0; index < MAX_GEN; index++ )
  185.                     {
  186.                         cout << "Set # " << (index + 1) << " is ";
  187.                         for( int index2 = 0; index2 < 6; index2++ )
  188.                         {
  189.                             cout << calc->array10[index]->set[index2] << ' ';
  190.                         }
  191.                         cout << endl;
  192.                         cout << "Reds " << calc->array10[index]->reds << "  ";
  193.                         cout << "Whites " << calc->array10[index]->whites << "  ";
  194.                         cout << "Blues " << calc->array10[index]->blues << endl;
  195.                         cout << "Odds " << calc->array10[index]->odds << "  ";
  196.                         cout << "Evens " << calc->array10[index]->evens << endl;
  197.                         cout << "Numbers due to be drawn soon: ";
  198.                         for( int index3 = 0; index3 < 6; index3++ )
  199.                         {
  200.                             if( calc->array10[index]->distrib[index3] == 1 )
  201.                             {
  202.                                 cout << calc->array10[index]->set[index3] << ' ';
  203.                             }
  204.                         }
  205.                         cout << endl;
  206.                         cout << "Protected numbers: ";
  207.                         for(int index4 = 0; index4 < 6; index4++ )
  208.                         {
  209.                             if( calc->array10[index]->protect[index4] == 1 )
  210.                             {
  211.                                 cout << calc->array10[index]->set[index4] << ' ';
  212.                             }
  213.                         }    
  214.                         cout << endl << endl;
  215.                     }
  216.                     cout << "A protected number is either a member of a hot pair, or" << endl;
  217.                     cout << "a likely number to come up in the next draw." << endl;
  218.                     cout << "In order to get a good set, some of these numbers may have" << endl;
  219.                     cout << "to be changed, so the protection is removed." << endl << endl;
  220.                     cout << "The statistics for the last draw:" << endl;
  221.                     calc->read_file();
  222.                     cout << "Odds: " << calc->record[0]->odds;
  223.                     cout << "  " << "Evens: " << calc->record[0]->evens;
  224.                     cout << "  " << "Reds: " << calc->record[0]->reds;
  225.                     cout << "  " << "Whites: " << calc->record[0]->whites;
  226.                     cout << "  " << "Blues: " << calc->record[0]->blues;
  227.                     cout << endl << endl;
  228.                     
  229.                     cout << "Bonus substitution set: ";
  230.                     calc->p_set = new a_set;
  231.                     while( (calc->predict_set()) == false 
  232.                                 || calc->p_set->the_set[0] == 0 ){;}
  233.                     for( int i = 0; i < 6; i++ )
  234.                     {
  235.                         cout << calc->p_set->the_set[i] << ' ';
  236.                     }
  237.                     delete( calc->p_set );
  238.                     cout << endl << endl;
  239.                     
  240.                     cout << "Hot pairs used for this number generation: " << endl;
  241.                     for( int x1 = 0; x1 < 10; x1++ )
  242.                     {
  243.                             cout << "Pair # ";
  244.                             if( x1 < 9 )
  245.                             {
  246.                                 cout << ' ';
  247.                             }
  248.                             cout << (x1 + 1) << " is: ";
  249.                             if( calc->ten_hot_pairs[x1][0] < 10 )
  250.                             {
  251.                                 cout << ' ';
  252.                             }
  253.                             cout << calc->ten_hot_pairs[x1][0] << ' ';
  254.                             if( calc->ten_hot_pairs[x1][1] < 10 )
  255.                             {
  256.                                 cout << ' ';
  257.                             }
  258.                             cout << calc->ten_hot_pairs[x1][1] << endl;
  259.                     }
  260.                     cout << endl << endl;
  261.                     cout << "Your ten number sets are: " << endl;
  262.                     for( int print = 0; print < MAX_GEN; print++ )
  263.                     {
  264.                         for( int print2 = 0; print2 < 6; print2++ )
  265.                         {
  266.                             if( calc->array10[print]->set[print2] < 10 )
  267.                             {
  268.                                 cout << ' ';
  269.                             }
  270.                             cout << calc->array10[print]->set[print2] << ' ';
  271.                         }
  272.                         cout << endl;
  273.                         delete( calc->array10[print] );
  274.                     }
  275.                     cout << "Scroll up the window for the statistics on these numbers!";
  276.                     cout << endl << endl;
  277.                     calc->clear_records();
  278.                 }
  279.                 break;
  280.             }
  281.             
  282.             case 4:
  283.                 {    
  284.                     // check if the file exists, and if so, if the user
  285.                     // wants to over-write it. default is true if no file exists.
  286.                     if( (calc->check_for_file()) == true )
  287.                         {
  288.                             cout << "Updating Database!" << endl;
  289.                             cout << "Begin with the oldest draw, working up to the most recent" << endl;
  290.                             cout << "Enter numbers in the form <number> <dot> <number>" << endl;
  291.                             cout << "Example:  12.17.23.34.42.50" << endl;
  292.                             cout << "Then enter the date (Example: 11/27/91) with slashes" << endl;
  293.                             cout << "Enter a q ( on line ->  Set?: ) to quit!" <<endl << endl;
  294.                             
  295.                             
  296.                             // init the class vars
  297.                             calc->clear_user_input();
  298.                             
  299.                             bool run = true;
  300.                             
  301.                         if( calc->read_file() == true )
  302.                         {
  303.                             do {
  304.                                     cout << "Set?: ";
  305.                                     cin >> calc->user_input;
  306.                                     run = ( calc->update_struct_file() );
  307.                                     cout << endl;
  308.                                     
  309.                                     if( run == true )
  310.                                     {
  311.                                         cout << "Date?: ";
  312.                                         cin >> calc->record[0]->date;
  313.                                         for( int indx = 0; indx < 20; indx++ )
  314.                                         {
  315.                                             if( (calc->record[0]->date[indx] == 'q') ||
  316.                                                  (calc->record[0]->date[indx] == 'Q') )
  317.                                             {
  318.                                                 run = false;
  319.                                                 calc->clear_records();
  320.                                                 break;
  321.                                             }
  322.                                         }
  323.                                                 
  324.                                     }
  325.                                     cout << endl;
  326.                                     
  327.                                     if( run == true )
  328.                                     {
  329.                                         cout << "Set # " << 1 << " is: ";
  330.                                         for( int index = 0; index < 6; index++ )
  331.                                         {
  332.                                             cout << calc->record[0]->set[index] << ' ';
  333.                                         }
  334.                                         cout << endl;
  335.                                         cout << "Date: " << calc->record[0]->date;
  336.                                         cout << endl << endl;
  337.                                     }
  338.  
  339.                             } while( run == true );
  340.                             
  341.                             if( (calc->save_whole_file()) == true )
  342.                             {
  343.                                 cout << "Update Successful!" << endl;
  344.                                 calc->clear_records();
  345.                                 break;
  346.                             } else {
  347.                                 calc->clear_records();
  348.                                 cout << "Error: No Data Written To Disk!!" << endl;
  349.                                 break;
  350.                                 }
  351.                         } else {
  352.                             cout << "No File Exists!!" << endl;
  353.                             break;
  354.                             }
  355.                         break;    
  356.                     }
  357.                 }
  358.                 
  359.                 case 5:
  360.                 {    
  361.                     // check if the file exists, and if so, if the user
  362.                     // wants to over-write it. default is true if no file exists.
  363.                     if( (calc->check_for_file()) == true )
  364.                         {
  365.                             cout << "Editing Database!" << endl << endl;
  366.                             cout << "Enter the record number to begin editing (0 for default): ";
  367.                             cin >> calc->user_request;
  368.                             cout << endl << endl;
  369.                             cout << "Enter numbers in the form <number> <dot> <number>" << endl;
  370.                             cout << "Example:  12.17.23.34.42.50" << endl;
  371.                             cout << "Then enter the date (Example: 11/27/91) with slashes" << endl;
  372.                             cout << "Enter a q ( on line ->  Set?: ) to quit!" <<endl << endl;
  373.                             
  374.                             
  375.                             // init the class vars
  376.                             calc->clear_user_input();
  377.                             
  378.                             bool run = true;
  379.                             
  380.                         if( calc->read_file() == true )
  381.                         {
  382.                             if( calc->user_request == 0 )
  383.                             {
  384.                                 calc->user_request = (calc->number_of_records + 1);
  385.                                 cout << "Begin adding sets with set# " << calc->user_request << endl << endl;
  386.                             }
  387.                             
  388.                             do {
  389.                                     
  390.                                     cout << "Set?: ";
  391.                                     cin >> calc->user_input;
  392.                                     run = ( calc->edit_struct_file() );
  393.                                     cout << endl;
  394.                                     
  395.                                     if( run == true )
  396.                                     {
  397.                                         cout << "Date?: ";
  398.                                         cin >> calc->record[(calc->user_request - 1)]->date;
  399.                                         for( int indx = 0; indx < 20; indx++ )
  400.                                         {
  401.                                             if( (calc->record[(calc->user_request - 1)]->date[indx] == 'q') ||
  402.                                                  (calc->record[(calc->user_request - 1)]->date[indx] == 'Q') )
  403.                                             {
  404.                                                 run = false;
  405.                                                 calc->clear_records();
  406.                                                 break;
  407.                                             }
  408.                                         }
  409.                                                 
  410.                                     }
  411.                                     cout << endl;
  412.                                     
  413.                                     if( run == true )
  414.                                     {
  415.                                         cout << "Set # " << (calc->user_request) << " is: ";
  416.                                         for( int index = 0; index < 6; index++ )
  417.                                         {
  418.                                             cout << calc->record[(calc->user_request - 1)]->set[index] << ' ';
  419.                                         }
  420.                                         cout << endl;
  421.                                         cout << "Date: " << calc->record[(calc->user_request - 1)]->date;
  422.                                         cout << endl << endl;
  423.                                     }
  424.                                     calc->user_request++;
  425.  
  426.                             } while( run == true );
  427.                             
  428.                             if( (calc->save_whole_file()) == true )
  429.                             {
  430.                                 cout << "Update Successful!" << endl;
  431.                                 calc->clear_records();
  432.                                 break;
  433.                             } else {
  434.                                 calc->clear_records();
  435.                                 cout << "Error: No Data Written To Disk!!" << endl;
  436.                                 break;
  437.                                 }
  438.                         } else {
  439.                             cout << "No File Exists!!" << endl;
  440.                             break;
  441.                             }
  442.                         break;    
  443.                     }
  444.                 }
  445.                 
  446.             case 6:
  447.                 {
  448.                     if( calc->read_file() == false ) { cout << "Error: can't open file!" << endl; }
  449.                     int which_record = 0;
  450.                     cout << endl;
  451.                     cout << "Delete Records starting from?: ";
  452.                     cin >> which_record;
  453.                     calc->number_of_records = which_record;
  454.                     cout << endl <<endl;
  455.                     if( calc->save_whole_file() == false )
  456.                     {
  457.                          cout << "Error: can't save file!" << endl;
  458.                     } else {
  459.                         cout << "Data saved to disk!" << endl << endl;
  460.                         calc->clear_records();
  461.                         }
  462.                     break;
  463.                 }
  464.                 
  465.                 case 7:
  466.                 {
  467.                     int which_one = 0;
  468.                     calc->clear_user_input();
  469.                     if( calc->read_file() == false )
  470.                     {
  471.                          cout << "Error: can't read file!" << endl;
  472.                          break;
  473.                     }
  474.                     cout << "Delete Which Record?: ";
  475.                     cin >> which_one;
  476.                     cout << endl;
  477.                     for( int pass1 = 0; pass1 < calc->number_of_records; pass1++ )
  478.                     {
  479.                         if( pass1 == (which_one - 1) )
  480.                         {
  481.                             pass1++;
  482.                         } 
  483.                         if( pass1 < (which_one - 1) )
  484.                         {
  485.                             temp[pass1] = calc->record[pass1];
  486.                         }
  487.                         if( pass1 > (which_one - 1) )
  488.                         {
  489.                             temp[pass1 - 1] = calc->record[pass1];
  490.                         }
  491.                     }
  492.                     
  493.                     calc->number_of_records--;
  494.                     
  495.                     for( int pass2 = 0; pass2 < calc->number_of_records; pass2++ )
  496.                     {
  497.                         calc->record[pass2] = temp[pass2];
  498.                     }
  499.                     
  500.                     calc->simple_save();
  501.                     calc->clear_records();
  502.                     cout << endl << "Finished!" << endl << endl;
  503.                     break;
  504.                 }
  505.                 
  506.             case 8:
  507.                 {
  508.                     int which = 0;
  509.                     calc->clear_user_input();
  510.                     if(calc->read_file() == false ) 
  511.                     { 
  512.                         cout << "Error: can't open file!" << endl; 
  513.                         break;
  514.                     }
  515.                     cout << "Enter number of record to change: ";
  516.                     cin >> which;
  517.                     cout << endl;
  518.                     for( int pass = 0; pass < 6; pass++ )
  519.                     {
  520.                         cout << "Set # " << which << "  number: " << (pass + 1) << " = ";
  521.                         cin >> temp[which - 1]->set[pass];
  522.                         cout << endl;
  523.                     }
  524.                     cout << "Set # " << which << " date = ";
  525.                     cin >> temp[which - 1]->date;
  526.                     cout << endl;
  527.                     cout << "Finished!" << endl << endl;
  528.                     for( int pass1 = 0; pass1 <= calc->number_of_records; pass1++ )
  529.                     {
  530.                         if( pass1 == (which - 1) )
  531.                         {
  532.                             pass1++;
  533.                         } 
  534.                         if( pass1 < (which - 1) )
  535.                         {
  536.                             temp[pass1] = calc->record[pass1];
  537.                         }
  538.                         if( pass1 > (which - 1) )
  539.                         {
  540.                             temp[pass1] = calc->record[pass1 - 1];
  541.                         }
  542.                     }
  543.                     
  544.                     calc->number_of_records++;
  545.                     
  546.                     for( int pass2 = 0; pass2 < calc->number_of_records; pass2++ )
  547.                     {
  548.                         calc->record[pass2] = temp[pass2];
  549.                     }
  550.                     
  551.                     calc->simple_save();
  552.                     calc->clear_records();
  553.                     break;
  554.                 }
  555.                         
  556.             case 9: { quit = true; }
  557.             
  558.             default: { break; }
  559.         }
  560.         
  561.     } while( quit == false || quit != true );
  562.     delete( calc );
  563.     exit( 0 );
  564. }
  565.  
  566. void print_main_menu( void )
  567. {
  568.     cout << "Choose one of the following: " << endl << endl;
  569.     cout << "1 for new database (completely erase data and begin new)" << endl;
  570.     cout << "2 to view database" << endl;
  571.     cout << "3 to generate numbers" << endl;
  572.     cout << "4 to enter last numbers drawn (starts at beginning of database)" << endl;
  573.     cout << "5 to enter more sets (starts at the end of database)" << endl;
  574.     cout << "6 to delete records (cuts database off after selected number)" << endl;
  575.     cout << "7 to delete a single record" << endl;
  576.     cout << "8 to insert a single record" << endl;
  577.     cout << "9 to quit" << endl;
  578.     
  579.     cout << endl << endl;
  580. }
  581.  
  582. bool check_for_quit( char *an_array, int size )
  583. {
  584.     // cycle through the string to look for a 'q'
  585.     for( int index = 0; index < size; index++ )
  586.     {
  587.         if( (an_array[size] == 'q') || (an_array[size] == 'Q') )
  588.         {
  589.             return true; // true if the user wants to quit
  590.         }
  591.     }
  592.     return false; // false if the user wishes to continue
  593. }
  594.  
  595. bool check_file( void )
  596. {
  597.     // checks if the file exists, and if so, if the user
  598.     // wants to over-write it.  default is true if no file exists
  599.     bool write_data = true;
  600.     char answer = NULL;
  601.     
  602.     if( (calc->check_for_file()) == true )
  603.     {
  604.         do {
  605.                 cout << "File Exists!!!!" << endl;
  606.                 cout << "Over-Write Existing File ?? ( y or n ): ";
  607.                 cin >> answer;
  608.                 cout << endl;
  609.                 switch( answer )
  610.                 {
  611.                     case 'y': case 'Y':
  612.                     {
  613.                         break;
  614.                     }
  615.                     case 'n': case 'N':
  616.                     {
  617.                         write_data = false;
  618.                         break;
  619.                     }
  620.                     default:
  621.                     {
  622.                         cout << "That is not one of the choices!" << endl << endl;
  623.                         answer = NULL;
  624.                     }
  625.                 }
  626.             } while( answer == NULL );
  627.     }
  628.     return write_data;
  629. }